<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>

</body>
<script>
  // https://juejin.cn/post/7049659144344698893
  // setTimeout 的执行示例
  var date1 = Date.now()
  console.log('setTimeout 执行的时间戳1：', date1)
  setTimeout(() => {
    var date2 = Date.now()
    console.log('setTimeout 执行的时间戳2：', date2)
    console.log('setTimeout 时差：', date2 - date1)
  }, 0)

  // messageChannel 的执行示例
  var channel = new MessageChannel()
  var port1 = channel.port1;
  var port2 = channel.port2;
  port1.onmessage = () => {
    var cTime2 = Date.now()
    console.log('messageChannel 执行的时间戳2:', cTime2)
    console.log('messageChannel 时差：', cTime2 - cTime1)
  }
  var cTime1 = Date.now()
  console.log('messageChannel 执行的时间戳1:', cTime1)
  port2.postMessage(null)
</script>

</html>